package com.shimi.erp.utils;

import com.alibaba.fastjson.JSONObject;

public class JsonUtil {

    public static JSONObject createOKJSON() {
        JSONObject re = new JSONObject();
        re.put("code", 0);
        return re;
    }

    public static JSONObject createOKJSON(Object page) {

        JSONObject re = new JSONObject();
        re.put("code", 0);
        re.put("data", page);
        return re;
    }

    public static JSONObject createErrJSON() {
        JSONObject re = new JSONObject();
        re.put("code", -1);
        return re;
    }

    public static JSONObject createCodeJSON(int code) {
        JSONObject re = new JSONObject();
        re.put("code", code);
        return re;
    }

    public static JSONObject createErrJSON(String msg) {
        JSONObject re = new JSONObject();
        re.put("code", -1);
        re.put("msg", msg);
        return re;
    }

    public static JSONObject createErrJSON(Exception e) {
        try {
            Class<? extends Exception> mClass = e.getClass();
            return createErrJSON(mClass.getSimpleName() + ":" + mClass.cast(e).getMessage());
        } catch (Exception e2) {
            return createErrJSON(e.getMessage());
        }
    }
}
